#version 330 core
out vec4 FragColor;
  
in vec2 TexCoords;

uniform float exposure;
uniform sampler2D hdrBuffer;
uniform bool bHDR;

void main()
{         
    const float gamma = 2.2;
    vec3 hdrColor = texture(hdrBuffer, TexCoords).rgb;

    if(!bHDR)
    {
        FragColor = vec4(hdrColor, 1.0);
        return;
    }
  
    // Reinhard色调映射
    //vec3 mapped = hdrColor / (hdrColor + vec3(1.0));
    vec3 mapped = vec3(1.0) - exp(-hdrColor * exposure);
    // 伽马校正 
    mapped = pow(mapped, vec3(1.0 / gamma));
  
    FragColor = vec4(mapped, 1.0);
}